/**
   画分页控件js
**/

  function drawPagination(wrapper,current_page,record_per_page,total_record,url)
  {
     /*var page_num ; //总页数
     if(total_record%record_per_page==0)
     {
       page_num = total_record/record_per_page;
     }
     else
     {
     	page_num = total_record/record_per_page+1;
     }*/
     
     var page_num = Math.ceil(total_record/record_per_page);
     
     var html="";
     
     if(current_page > 1){
         var prev_page = parseInt(current_page)-1;
    	 html +=  "<a href=\""+url+prev_page+"\"  class=\'prev\' title=\'上一页 \'></a>";
     }else{
    	 html +=  "<span class=\'prev\'></span>";
     }
     
     //输入分页
     for(var i=1;i<= page_num;i++)
     {
        if(current_page==i)
        {
        	html += "<span class=\'current\'>"+current_page+"</span>";
        }
        else
        {
            var begin_num = current_page -5 ;
            var end_num = current_page + 5;
            
            if(begin_num < 1)
            {
              begin_num = 1;
              end_num = 10;
            }
            
            if(end_num > page_num)
            {
              end_num = page_num;
              begin_num = page_num -9;
            }
            
            
            //如果是第一页和最后一页则存在
			if(i==1 || i==page_num) 
			{
			   html += "<a  href=\""+url+i+"\" class=\'item\'>"+i+"</a>";
			}     
			//只显示当前页面的前五页和后五页  
	        else if( (i>begin_num) && (i<end_num))
	         {
	          	 html += "<a  href=\""+url+i+"\" class=\'item\'>"+i+"</a>";
	         }
	         //当前页面的前五页和后五页范围外的显示为省略号
	         else
	         {
	             //if(i= (page_num-1))
	             //{
	               // html += "...";
	             //}
	             
	         }
        }
     }
     
     if(current_page<page_num)
     {
         var next_page = parseInt(current_page)+1;//paseInt 不加的话会当成字符串拼成。确保算术运算fufeilong
         html += "<a href=\""+url+next_page+"\" class=\'next\' title=\'下一页\'></a> ";
     }else{
    	 html += "<span class=\'next\'></span> ";
     }
     
     //html += " <span> 到第<input id=\"input_"+wrapper+"\" type=\"text\" size=\"2\" value=\"\" /> 页";
     //html += "<input type=\"button\"id=\"btn_"+wrapper+"\" onclick=\"callBack('"+wrapper+"','"+url+"')\"  class=\"btn\" value=\"确定\" /></span>";
     
     var _totleRecord = parseInt(total_record,10);
     var totalPages = (_totleRecord%record_per_page == 0)?(parseInt(_totleRecord/record_per_page)):(parseInt(_totleRecord/record_per_page) + 1);
     html += " <span class=\'total_num\'>共<ins>"+ totalPages +"</ins>页</span>";
     html += "<input type=\"hidden\"  value=\""+page_num+"\" type=\"text\" id=\"page_"+wrapper+"\" />";
     
     
     //分页代码放入容器中
     $("#"+wrapper).html(html);
     
     //如果只有一页内容，则隐藏分页栏
     if(_totleRecord <= record_per_page){
    	 $('#'+wrapper).hide();
     }
  }

function callBack(wrapper ,url) {
	var pageNo = $("#input_"+wrapper).val();//页面编号
	var pageNum = $("#page_"+wrapper).val();//页数
     
    if ($.trim(pageNo) == '') {
    	showAlert('请输入您要跳转的页码！');
	} else if(isNaN(parseInt(pageNo))) {
    	showAlert('输入的页码必须为数字！');
	} else if(parseInt(pageNo)<0 ||parseInt(pageNo)>parseInt(pageNum)) {
    	$("#input_"+wrapper).val("1");
	} else {
    	window.location = url+pageNo;
	}
}